package org.apache.database.pool;

import org.apache.database.entity.ConfigInfos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {
    protected Connection connection;

    public DatabaseConnection(ConfigInfos connectInfo) {
        try {
            if (connectInfo.check()){
                System.out.println("数据库配置错误");
                return;
            }
            String url = connectInfo.getUrlAddress();
            connection= DriverManager.getConnection(url,connectInfo.getUser(),connectInfo.getPass());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }
}
